#include<iostream>
#include<string>

using namespace std;


class Solution 
{
public:
    string addStrings(string num1, string num2)
    {
        string sum;
        int x = 0;
        int i = num1.size() - 1;
        int j = num2.size() - 1;
        while (i >= 0 && j >= 0)
        {
            int counts = (num1[i--] - '0') + (num2[j--] - '0');

            int count = (counts % 10) + x;
            if (count == 10)
            {
                count = 0;
                x = 1;
            }
            else
            {
                x = counts / 10;

            }

            sum += (count + '0');

        }
        while (i >= 0)
        {
            int counts = (num1[i--] - '0');
            int count = (counts % 10) + x;
            if (count == 10)
            {
                count = 0;
                x = 1;
            }
            else
            {
                x = counts / 10;

            }
            sum += (count + '0');

        }
        while (j >= 0)
        {
            int counts = (num2[j--] - '0');
            int count = (counts % 10) + x;
            if (count == 10)
            {
                count = 0;
                x = 1;
            }
            else
            {
                x = counts / 10;

            }
            sum += (count + '0');
        }
        if (x > 0)
        {
            sum += (x + '0');
        }


        reverse(sum.begin(), sum.end());
        return sum;




    }
    


    string multiply(string num1, string num2)
    {
        string r;
        string num;
        if (num1[0] == '0'&& num1.size()==1 || num2[0] == '0' && num2.size() == 1)
        {
            num = '0';
            return num;
        }
       
        int i = num2.size() - 1;
        int j = num1.size() - 1;
        int s = 0;
        int tmp = j;
        while (i >= 0)
        {
            string n;
            while (tmp >= 0)
            {
                int count = 0;
                int counts = (num1[tmp] - '0') * (num2[i] - '0') + s;
                count = counts % 10;
                if (counts > 9)
                {
                    s = counts / 10;
                }
                else
                {
                    s = 0;
                }

                n += (count+'0');
                //pow(10, num1.size() - tmp - 1);
                 tmp--;
            }
            if (s != 0)
            {
                n += (s + '0');
                s = 0;
            }
            reverse(n.begin(), n.end());

            int p = i;
            while (p < num2.size() - 1)
            {
                n +=  '0';
                p++;

            }
            num=addStrings(num, n);
 
            tmp = j;
            i--;
             
        }
        
        

   
        return num;





    }
};




int main()
{
    string n1 = "99";
    string n2 = "9";
    Solution sum;
    string num=sum.multiply(n1,n2);
    cout << num;







    return 0;
}